package IdeaGui;

import java.util.Hashtable;

/**
 * User: Mike
 * Date: 11/24/11
 * ..
 * keeps track of bottle stats. main output is the bottleAbv, bottleVolume, bottleRateByRate
 */

public class BottleCalcs {

    private static final double MILLI_TO_MIN = (1.0 / 1000.0) * (1.0 / 60.0);
    private Long startTime;
    private double rate;
    private double startAbv;

    private int bottleNumber;
//    private List<Double> bottleAbv = new ArrayList<Double>();
//    private List<Double> bottleVol = new ArrayList<Double>();
//    private List<Double> bottleRateByRate = new ArrayList<Double>();

    Hashtable<String, Double> bottleAbv = new Hashtable<String, Double>();
    Hashtable<String, Double> bottleVol = new Hashtable<String, Double>();
    Hashtable<String, Double> bottleRateByRate = new Hashtable<String, Double>();
    Hashtable<String, Double> bottleRateByBottle = new Hashtable<String, Double>();
//    private double bottleVolByBottle = 150;


    public BottleCalcs(Long startTime, double rate, int bottleNumber) {
        this.startTime = startTime;
        this.rate = rate;
        this.bottleNumber = bottleNumber;
    }

    public void newBottle(int bottleNum, double rate2, double abv2, double bottleVol) {
        if (bottleNum > 0) {
            assert !Double.isNaN(rate2) : "BottleCalc: rate 2 was NaN";
            Long stopTime = System.currentTimeMillis();
            rate = (rate - rate2) / 2.0;
            bottleNumber = bottleNum;
            if (bottleNumber == 0) {
            } else if (bottleNumber == 1)
                startAbv = abv2;
            else {
                // do the calculations for this round
                double aveAbv = (startAbv + abv2) / 2.0;
                double totalml = rate * (stopTime - startTime) * MILLI_TO_MIN;
                bottleAbv.put(String.valueOf(bottleNum), aveAbv);
//                bottleVol.put(String.valueOf(bottleNum), totalml);
                bottleRateByRate.put(String.valueOf(bottleNum), rate);
            }
            // set the values for the next bottle
            startAbv = abv2;
            startTime = stopTime;
            rate = rate2;


            // calc rate by bottle vol
            double time = (startTime - stopTime) * MILLI_TO_MIN;
            bottleRateByBottle.put(String.valueOf(bottleNum), bottleVol / MILLI_TO_MIN);
        }
    }

    public Hashtable<String, Double> getBottleAbv() {
        return bottleAbv;
    }

    public Hashtable<String, Double> getBottleVol() {
        return bottleVol;
    }

    public Hashtable<String, Double> getBottleRateByRate() {
        return bottleRateByRate;
    }

    public Hashtable<String, Double> getBottleRateByBottle() {
        return bottleRateByBottle;
    }
}
